More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
post
page
Python IDE Dashboard

Frame-Based Animation on the BBC Micro

One of the fun things you can do in BBC BASIC is create frame-based animations using custom characters.

In this tutorial, we will explain how the following program makes a stickman walk from left to right across the screen.

Here is the code for our animation:

10 MODE 2
20 VDU 23,226,24,24,16,58,84,16,40,72
30 YELLOW$=CHR$(17)+CHR$(3)
40 VDU 23,227,24,24,80,60,16,16,40,36
50 FOR I%=0 TO 19
60    CLS
70    SPRITE$=CHR$(226)
80    IF I%MOD2=0 THEN SPRITE$=CHR$(227)
90    PRINT TAB(I%,10) YELLOW$ SPRITE$
100    PRINT TAB(0,11) "--------------------"
110   FOR WAIT%=1 TO 1000:NEXT WAIT%
120 NEXT I%
130 END

You can use an online BBC Basic emulator to complete his challenge:

Let’s break down this code step-by-step.

Step 1: Choosing a Screen Mode

10 MODE 2

MODE 2 sets the screen to:

  • 20 columns wide
  • 32 rows high
  • 8 colours available
  • Large blocky pixels (great for custom characters!)

This mode is perfect for simple sprite animation.

Step 2: Creating Custom Characters

Check our blog post on how to create your own ASCII characters to reuse in your animation.

Using this online custom character code generator we will create two stickman characters as follows:

First Stickman Frame
20 VDU 23,226,24,24,16,58,84,16,40,72

This redefines character 226.

The numbers after 226 describe the 8 rows of pixels that make up the character.

Each number represents one row of 8 pixels:

  • Each bit in the number turns a pixel ON (1) or OFF (0).
  • So you are effectively designing an 8×8 sprite.

This first design is one pose of the stickman.

Second Stickman Frame
40 VDU 23,227,24,24,80,60,16,16,40,36

This defines character 227.

This is a slightly different pose — maybe the legs are swapped.

Now we have two frames:

  • Character 226 → Stickman pose A
  • Character 227 → Stickman pose B

Switching between them will create the illusion of walking.

Step 3: Setting the Colour

30 YELLOW$=CHR$(17)+CHR$(3)

CHR$(17) tells the BBC Micro we are changing text colour.
CHR$(3) sets the colour to yellow.

So YELLOW$ stores the control codes needed to print yellow text.

Later, when we print the sprite, we include YELLOW$ so the stickman appears yellow.

Remember, in Mode 2, you can choose amongst these 8 colours:

Step 4: Creating the Animation Loop

50 FOR I%=0 TO 19

This loop runs 20 times.
I% controls:

  • The horizontal position of the stickman
  • Which animation frame to use

Step 5: Clearing the Screen

60 CLS

CLS clears the screen each frame.

This is essential for animation — otherwise, the old stickman positions would remain visible.

Step 6: Choosing the Animation Frame

70 SPRITE$=CHR$(226)
80 IF I%MOD2=0 THEN SPRITE$=CHR$(227)

Here is the clever bit!

By default, we use character 226:

If I% MOD 2 = 0, we switch to character 227.

MOD means remainder after division. So:

  • When I% is even → frame 227
  • When I% is odd → frame 226

This alternates the stickman pose every loop, an essential part of our frame-based animation!

Step 7: Moving Across the Screen

90 PRINT TAB(I%,10) YELLOW$ SPRITE$

TAB(I%,10) moves the cursor to:

  • Column = I%
  • Row = 10

Since I% increases each loop, the stickman moves right.

Then we print the colour code and the custom character sprite, so the stickman appears to walk across the screen.

Step 8: Drawing the Ground

100 PRINT TAB(0,11) "--------------------"

This prints a simple floor under the stickman.
It helps give the illusion that the character is walking.

Step 9: Slowing It Down

110 FOR WAIT%=1 TO 1000:NEXT WAIT%

This is a delay loop. Without it, the animation would move too fast to see. The larger the number, the slower the animation.

Step 10: Repeat

120 NEXT I%
130 END

The loop repeats until the stickman reaches the right side of the screen.
Then the program ends.

🎬 How Frame-Based Animation Works

To sum it up, frame-based animation works by:

  • Creating multiple versions of a character (frames)
  • Rapidly switching between them
  • Moving the position slightly each time
  • Adding a small delay

Your brain fills in the gaps and sees movement! This is exactly how early video games worked.

Tagged with: ,

Drawing Shapes on a BBC Micro

In this tutorial, you will learn how to use the MOVE, DRAW, and PLOT commands in BBC BASIC to create and fill shapes.

By the end you will understand:

  • How screen modes work
  • How coordinates work
  • How to draw triangles, rectangles, circles and ellipses
  • How to change colours
  • How to fill shapes properly

You can use an online BBC Basic emulator to complete his challenge:

️BBC Micro Screen Modes

Before we start drawing on the screen let’s investigate the different screen modes available on a BBC Micro.

Effectively using BBC Basic you can change the screen Mode and resolution using the following instruction:

MODE number

When creating a computer program in BBC Basic, there are 8 modes to choose from as described below:

Mode Type Resolution Colours
MODE 0 Graphics 640 × 256 2
MODE 1 Graphics 320 × 256 4
MODE 2 Graphics 160 × 256 16
MODE 3 Text 80 × 25 text 2
MODE 4 Graphics 320 × 256 2
MODE 5 Graphics 160 × 256 4
MODE 6 Graphics 320 × 256 2
MODE 7 Teletext 40 × 25 text 8 (Teletext)

Tip: MODE 2 is great for colourful drawings.

Understanding Coordinates

  • (0,0) is the bottom-left of the screen
  • X increases to the right, from 0 to 1279.
  • Y increases upwards, from 0 to 1023

Note that the (X,Y) coordinates help you position your “pen” on a 1280 x 1024 canvas/screen whatever mode you are opting for for your programme. The resolution set by selecting a mode only impacts on the size of the pixels displayed on screen. (Hence on the number of pixels you can display on the screen). For instance with mode 2, each pixel will be 8 graphic units wide by 4 graphic units wide. Hence you can only display 160 pixels accross the screen. (X,Y) coordinates used when drawing on the screen use graphic units (X between 0 and 1279 and Y between 0 and 1023) instead of pixels.

MOVE() and DRAW() to Draw Lines ✏️

To draw lines and shapes we will mainly use two commands: MOVE() and DRAW().

MOVE moves without drawing.
DRAW draws a line from the current position.

For instance:

10 MODE 2
20 MOVE 100,100
30 DRAW 200,100

This draws a horizontal line on screen.

Drawing a Shape

To draw a shape, we will need to draw each line one by one, joining the relevant set of (X,Y) coordinates.

For instance to draw a rectangle:

10 MODE 2
20 MOVE 150,100
30 DRAW 350,100
40 DRAW 350,200
50 DRAW 150,200
60 DRAW 150,100

Changing Colours

Use GCOL() instruction to change drawing colour:

GCOL 0,2

The second number selects the colour. You can start using the following colour codes for your drawings:

Understanding the PLOT Command

The PLOT() command can be used as either as an alternative to or alongside the DRAW() and MOVE() commands. It enables to draw more complex shapes including circles and ellipses. It is also used to “close shapes” and fill them in with a colour.

The structure of this command is:

PLOT mode, x, y

The first parameter (mode) tells BBC BASIC what type of graphics action to perform.

Filling a Triangle

To fill a triangle, use:

PLOT 85, x, y

85 fills a triangle using:

  • The last two graphics points visited
  • The new coordinate (x,y)

Example:

10 MODE 2
20 GCOL 0,2

30 MOVE 200,100
40 DRAW 300,200
50 DRAW 100,200
70 PLOT 85,200,100

Using BBC Basic it is possible to condense your code by writting multiple instructions on the same line using a colon (:) between each instruction: e.g.

10 MODE 2
20 GCOL 0,2

30 MOVE 200,100:DRAW 300,200:DRAW 100,200:PLOT 85,200,100

Filling a Rectangle or Parallelogram

To fill a parallelogram (including rectangles), use:

PLOT 69, x, y

69 fills the shape formed by:

  • The last three visited points
  • The new coordinate

Example:

10 MODE 2
20 GCOL 0,1

30 MOVE 150,100
40 DRAW 350,100
50 DRAW 350,200

60 GCOL 0,3
70 PLOT 69,150,200

Drawing Circles

The command to draw a circle outline is:

PLOT 145, x, y, radius

Example:

10 MODE 2
20 GCOL 0,6
30 PLOT 145,300,150,50

145 = circle outline.

Filled Circle

The command to draw a filled circle is:

PLOT 153,300,150,50

153 = filled circle.

Drawing Ellipses

The command to draw an ellipse outline is:

PLOT 147, x, y, radiusX, radiusY

Example:

10 MODE 2
20 GCOL 0,5
30 PLOT 147,300,150,80,40

Filled Ellipse

The command to draw a filled ellipse is:

PLOT 135, x, y, radiusX, radiusY

PLOT 155,300,150,80,40

Summary Table

Shape Outline Mode Filled Mode
Triangle Use DRAW 85
Rectangle / Parallelogram Use DRAW 69
Circle 145 153
Ellipse 147 155

Challenge #1: Drawing Flags by Combining Shapes

Use all the skills described in this blog post to draw the following flags n the screen:

Challenge #2: Complete the 3D Cube

Here is the code to draw a cube in 3D. However some edges are missing. Add the correct MOVE and DRAW commands to complete this code.

10 MODE 2
20 GCOL 0,7

30 REM Front square
40 MOVE 200,200
50 DRAW 400,200
60 DRAW 400,400
70 DRAW 200,400
80 DRAW 200,200

90 REM Back square
40 MOVE 250,250
50 DRAW 450,250
60 DRAW 450,450
70 DRAW 250,450
80 DRAW 250,250

150 REM Connect corners
160 MOVE 200,200
170 DRAW 250,250

180 MOVE 400,200
190 DRAW 450,250

200 REM Add code for the missing edges of our cube...

Extension Task:

  • Fill one face of the cube.
  • Use different colours for each face.
  • Animate the cube by shifting coordinates in a loop.
Tagged with: ,

Bitmap ASCII Characters for the BBC Micro

One of the features that made the BBC Micro such a powerful machine for games programming was the ability to redefine characters and turn text into graphics. Many classic BBC Micro games use custom characters to create sprites, icons and simple animations — all without a dedicated graphics engine.

In this post, you will learn:

  • What ASCII characters are on the BBC Micro
  • How characters are stored as 8×8 bitmaps
  • How the VDU 23 command works
  • How colour is applied to custom characters
  • How to design your own characters using an online tool
  • How to test them in a BBC BASIC emulator

By the end, you will be creating your own sprites using text characters — just like programmers did in the 1980s.

ASCII Characters on the BBC Micro

On the BBC Micro, each character you can print to the screen (letters, numbers, symbols) is represented internally as an 8×8 grid of pixels. Each pixel is either On or Off.

That means every character can be thought of as a tiny bitmap image.

Normally, these characters are built into the system ROM. However, BBC BASIC lets us redefine characters so they display any shape we want. (We will find out how later on in this post)

This is how many games created the different sprites for their games (player sprites, spaceships, enemies, aliens, etc…), all using text mode.

The 8×8 Bitmap Grid

Each character uses and 8×8 grid (8 rows, 8 columns)
Each row is stored as a single number between 0 and 255.

Why 255?
Because each row is actually an 8-bit binary number which is calculated by adding the value of each pixel on the row e.g.

So each one of the 8 rows can be replaced with an 8-bit number (value between 0 and 255):

Redefining Characters with VDU 23

BBC BASIC provides a special command for redefining characters:

VDU 23, character_number, row1, row2, row3, row4, row5, row6, row7, row8

For example:
VDU 23,226,66,36,126,219,189,189,36,102
This tells the BBC Micro to redefine the ASCII character 226, using the eight numbers to describe its pixel rows.

Once defined, the character can be printed like any other:
PRINT CHR$(226)

Applying Colour to Characters

On the BBC Micro, colour is controlled separately from the character bitmap.

In MODE 2, colours are set using control codes from 0 to 7 to access the following colours:

We can can define colours within our code as follows

RED$ = CHR$(17) + CHR$(1)
YELLOW$ = CHR$(17) + CHR$(3)

We can then apply these font colours when printing text or ASCII characters, including our custom made ASCII characters:
PRINT RED$ CHR$(226)
This makes it easy to reuse the same character in different colours.

Online BBC Basic ASCII Character Generator

You can generate your own ASCII characters using our online BBC Basic ASCII Character Generator:

Positioning Characters on the Screen

When writing games, you rarely want your character to appear at the top-left of the screen every time. BBC BASIC provides simple ways to position text characters anywhere on the screen, which works perfectly with custom characters. To do so we will use the TAB(X,Y) function:

RED$ = CHR$(17) + CHR$(1)
PRINT TAB(10,10) RED$ CHR$(226)

When using the TAB() function, BBC BASIC counts the columns and rows from the top-left corner of the screen:

  • X: Column numbers increase from left to right
  • Y: Row numbers increase from top to bottom

Screen Size:
In Mode 2 on the BBC Micro, the screen is configured for 16 colours (The 8 colours describe above using colour codes 0 to 7, and their flashing counterparts colour codes 8 to 15) and has the following text and graphics dimensions:

  • Text Columns: 20 characters per line
  • Text Rows: 32 rows
  • Graphics Resolution: 160 × 256 pixels

Using these dimnesions, here the code needed to place our ASCII character in each of the 4 corners of the screen:

RED$ = CHR$(17) + CHR$(1)
YELLOW$ = CHR$(17) + CHR$(3)
GREEN$ = CHR$(17) + CHR$(2)
BLUE$ = CHR$(17) + CHR$(4)
PRINT TAB(0,0) RED$ CHR$(226)       : REM Top-left corner
PRINT TAB(19,0) YELLOW$ CHR$(226)   : REM Top-right corner
PRINT TAB(0,31) GREEN$ CHR$(226)    : REM Bottom-left corner
PRINT TAB(19,31) BLUE$ CHR$(226)    : REM Bottom-right corner

If you try to print outside this range, the character may wrap around or disappear off screen.

The TAB(X,Y) approach is very useful in video games to position sprites and text on the screen and to implement movements of the different sprites in a frame based game.

You Task 1: Designing Your Own Characters


Create your own ASCII characters using our online BBC Basic ASCII Character Generator.
Use the auto-generated BBC Basic code and test it using an online BBC Basic Emulator.
Position your characters on the screen using the TAB(X,Y) approach.

You Task 2: Design Your Own Splash Screen

Using the same techniques, create your own splash screen for the game Space Invaders!

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Tagged with: ,

Football League Table using an API

In many modern programs and websites, data does not come from a file stored on your computer. Instead, it is often retrieved live from the internet. One of the most common ways this happens is through an API. In this challenge, we will learn how to use an online API to retrieve real football data and process it in a Python program.

What is an API?

API stands for Application Programming Interface.

In simple terms, an API is a way for one program to talk to another program. It allows software developers to request data or services from an external system in a controlled and predictable way.

For example:

  • A weather app uses an API to request today’s forecast
  • A travel website uses an API to retrieve flight prices
  • An e-commerce website (online shop) may use an API to retrieve up-to-date currency exchange rate
  • A football website uses an API to display league tables and player information

Instead of manually copying information from a website, a program can send a request to an API and receive the data automatically. This is extremely relevant especially when your program needs to access up-to-date data from an external source/supplier such as currency exchange rates, weather forecast data etc.

The Sports DB API

For this lesson, we will be using TheSportsDB API, which provides free access to a wide range of sports data, including:

  • English Premier League tables
  • Football teams and players
  • Stadiums (venues)
  • Match results and fixtures

You can explore everything the API offers by reading the official documentation here:
https://www.thesportsdb.com/documentation

Note that for the purpose of this task, we will be using the free API (using API key “123”) which only gives you restricted access to some of the sports data.

Understanding how to read API documentation is an important skill for any programmer. The documentation explains:

  • What data is available
  • What type of requests you can make
  • Which parameters you need to include in your request

Making an API Request with a URL

To access data from an API, you usually send a request using a URL.

This URL often contains a query string, which is the part of the URL that includes extra information (parameters) used to filter the data.

For example, an API URL might include:

  • The name of a league
  • The name of a player
  • A team ID or season year

These parameters tell the API exactly what data you want.
The available parameters and how to use them are explained in the API documentation.

When writing your Python program, you will:

  1. Send a request to the API using a URL
  2. Receive data back from the API
  3. Process (parse) that data so your program can use it

What is JSON?

When an API sends data back to your program, it usually uses a format called JSON.

JSON stands for JavaScript Object Notation, but it is widely used in many programming languages, including Python.

JSON is a structured data format that stores information using:

  • Key–value pairs
  • Lists (arrays)
  • Nested objects

A simplified example of JSON data may replicate the following structure:

  • A league has a name
  • A league contains teams
  • Each team has players
  • Each player has a name and position

This structure makes JSON easy for both humans and computers to read.

What Does “Parsing JSON” Mean?

When we say parsing JSON, we mean: Converting JSON data into a format that our program can understand and work with.

In Python, this usually means:

  • Turning JSON data into dictionaries and lists
  • Accessing values using keys
  • Looping through lists of data
  • Extracting only the information we need

For example, instead of displaying all the data returned by the API, you might:

  • Extract team names only
  • Find a specific player
  • Display league positions in a table format

Parsing allows you to transform raw data into useful information.

The Challenge

Your task is to explore TheSportsDB API and write a Python program that retrieves and processes live football data.

You should begin by carefully reading the API documentation to understand which requests are available and which parameters you need to use.

Task Ideas
Your program should complete tasks such as:

    Allowing the user to enter the name of a football player and displaying the team they currently play for
    Displaying an up-to-date English Premier League table
    Allowing the user to enter the name of a venue and displaying the description of this venue and its capacity (number of spectators)

You will need to:

    Choose the correct API endpoint
    Build the request URL using the correct parameters
    Retrieve the JSON data
    Parse the JSON to extract the required information
    Display the results clearly to the user

⚠️ Important: You do not need to hard-code any football data into your program. All information should come directly from the API.

Python Code: Player Search

Here is an example of Python code to search for a player based on their name and return the search results: Full name of the players matching the search criteria and the club they play for.

Python Code: League Table

Here is an example of Python code to display an extract of the English Football Premiere League table for the current season!

Tagged with:

BBC Micro – Creating a Text-Based Adventure Story Game

This tutorial is the fourth of a set of lessons/tutorials that focus on:

BBC Micro Online Emulator

To complete these lessons, you do not need access to a physical BBC micro computer. You can use the following online emulator and type commands in your browser, without the need to install anything on your computer.

You may also find the following BBC Basic emulator quite handy for testing your own BBC Basic programs.

️ Upside-Down World — BBC BASIC Text Adventure Tutorial

You are about to create a game called “Upside-Down World”, a text-based adventure game inspired by the series Stranger Things. This game will let the player make choices that affect the story.

Story Setup

Here is the background context for this game:

  • You play as Eleven.
  • You discover a mysterious Gate to the Upside-Down world.
  • Your mission: find Will Byers, a friend of yours who is trapped in the Upside-Down.
  • At each point, the player must choose what to do next.
Step 1 — Planning the Game Structure
Step 1 — Planning the Game Structure

Our code will mainly be based on using the following BBC Basic commands:

  • PRINT → to show story text
  • INPUT → to get player choices
  • IF … THEN → to react to choices
  • GOTO → to move between story sections (using line numbers)

Each part of the story will have its own section in our program, for example:

  • From line 10 to 990: The title screen and introduction to the story line
  • From line 1000 The discovery of a gate to the Upside-Down
  • From line 1500 What happens if the player decides to run away from the gate
  • From line 2000 What happens if the player decides to go through the gate
  • etc.
Step 2 — Adding a Title Screen
Step 2 — Title Screen
10 MODE 7
20 PRINT "=============================="
30 PRINT "     UPSIDE-DOWN WORLD"
40 PRINT "=============================="
50 PRINT
60 PRINT "A Stranger Things Inspired Adventure"
70 PRINT
80 PRINT "Press ENTER to begin"
90 INPUT A$
100 GOTO 1000

This creates a simple intro screen.
You can test your game so far by using the RUN command:

RUN
Step 3 — Starting the Story
Step 3 — Starting the Story
1000 CLS
1010 PRINT "You are Eleven."
1020 PRINT "It is late at night in Hawkins."
1030 PRINT "Suddenly, you feel something strange..."
1040 PRINT
1050 PRINT "In the woods, you see a glowing GATE."
1060 PRINT
1070 PRINT "Do you:"
1080 PRINT "1 - Go through the Gate"
1090 PRINT "2 - Run back to town"
1100 PRINT
1110 INPUT "Enter 1 or 2: " choice

1120 IF choice = 1 THEN GOTO 2000
1130 IF choice = 2 THEN GOTO 1500
1140 GOTO 1110

The GOTO instruction on line 1140 means that if the player types something else (not option 1 or 2), the game asks the same question again.


Step 4 — Running Back to Town Path
Step 4 — Running Back to Town Path
1500 CLS
1510 PRINT "You run back towards Hawkins."
1520 PRINT "You tell Mike and Dustin about the Gate."
1530 PRINT
1540 PRINT "They decide you must go back and rescue Will!"
1550 PRINT
1560 PRINT "You return to the woods together..."
1570 PRINT
1580 PRINT "Press ENTER to continue"
1590 INPUT A$
1600 GOTO 2000

This brings the story back to the main mission.

Step 5 — Entering the Upside-Down
Step 5 — Entering the Upside-Down
2000 CLS
2010 PRINT "You step through the Gate..."
2020 PRINT
2030 PRINT "The world is dark and cold."
2040 PRINT "Strange sounds echo around you."
2050 PRINT
2060 PRINT "You must find Will before it's too late."
2070 PRINT
2080 PRINT "You see:"
2090 PRINT "1 - An old abandoned school"
2100 PRINT "2 - A dark tunnel leading underground"
2110 PRINT
2120 INPUT "Where do you go? (1 or 2): " choice

2130 IF choice = 1 THEN GOTO 3000
2140 IF choice = 2 THEN GOTO 4000
2150 GOTO 2120

Now the player can choose different paths.

Step 6 — One Example Location
Step 6 — One Example Location
3000 CLS
3010 PRINT "You enter the ruined school."
3020 PRINT "Desks are overturned."
3030 PRINT
3040 PRINT "You hear a noise upstairs..."
3050 PRINT
3060 PRINT "Do you:"
3070 PRINT "1 - Go upstairs"
3080 PRINT "2 - Hide and listen"
3090 PRINT
3100 INPUT "Choose 1 or 2: " choice

3110 IF choice = 1 THEN GOTO 5000
3120 IF choice = 2 THEN GOTO 6000
3130 GOTO 3100

From here, you will have to be creative with your story line. You can add monsters, clues, or even rescue scenes.

Step 7 — Suggested Storyline Ideas
Step 7 — Suggested Storyline Ideas

Here are a few ideas of some of the new scenes you can add to your story lines.

  • You collect some items in a room of the school (e.g. torch, radio, weapon)
  • You are face to face with a Demogordon (monster) in the school library, will you fight it or run away?
  • You find Will hiding in the school sports hall


Here are some possible endings for your game:

  • You rescue will successfully, and run back to the gate to escape from the Upside-Down
  • You rescue will successfully, and run back to the gate to escape from the Upside-Down but a Demogordon follows you through the gate…
  • The gate you used to access the Upside-Down is now closed so you too end up getting trapped in the Upside-Down
  • You cannot find Will anywhere and decided to escape through the gate. This would mean that you have failed the mission
Step 8 — Extra Challenges Ideas
Step 8 — Extra Challenges Ideas

There are so many ways you could make you game even more complex and engaging to play

Here are some suggestions of what you could add to the game:

⭐ Beginner Level:

  • Add another location in the Upside-Dow
  • Add more dialogue for each scene

⭐⭐ Intermediate Level:

  • Add a health score
  • Lose health when meeting a monster

⭐⭐⭐ Expert Level:

  • Add an inventory system
  • Give more options on different scenes based on the items the player has collected.
    For instance they can only go through the underground tunnel if they have previously collected a torch.

Example health system idea:
Towards the start of you code, initialise the players health to 100.

LET health = 100

When the players fight a Demagordon they lose some of their health score.

health = health - 20
PRINT "Health Score: "; health
IF health <= 0 THEN GOTO 9000
Step 6 — One Example Location
Game Over Example
9000 CLS
9010 PRINT "You collapse from your injuries..."
9020 PRINT
9030 PRINT "The Upside-Down has claimed another victim."
9040 PRINT
9050 PRINT "GAME OVER"
Tagged with: ,

BBC Micro – My First Program

This tutorial is the third of a set of lessons/tutorials that focus on:

BBC Micro Online Emulator

To complete these lessons, you do not need access to a physical BBC micro computer. You can use the following online emulator and type commands in your browser, without the need to install anything on your computer.

You may also find the following BBC Basic emulator quite handy for testing your own BBC Basic programs.

Writing, Testing and Editing Your First Program

The aim of this tutorial is for you to become confident at writing, editing and testing computer programs written in BBC Basic on a BBC Micro computer.

To do so, we will guide step by step to create a classic Magic 8 Ball program!

By the end of this tutorial you will know how to:

  • Enter a program in BBC BASIC
  • Run and test your program
  • Add, edit and delete lines of your program
  • Get more familiar with some essential BBC Basic instructions
  • Understand how each part of the Magic 8 Ball program works

To create our Magic 8 Ball program using BBC Basic, we will use a step by step approach using the following 15 steps! Make sure to complete all these steps in order and to keep track of your progress!

Step 1 - Starting a Program on the BBC Micro
Starting a Program on the BBC Micro
When you switch on a BBC Micro, you will see:

BBC Computer 32K
>

The > is the command prompt. This means the computer is ready for you to type commands or program lines.

To start writing a program, just type a line number followed by a command, for example:

10 PRINT "HELLO"

Press RETURN after each line.

Running Your Program

To run the whole program, type:

RUN

and press RETURN.

If you change the program, just type RUN again to test it.
To exit a program that is running, press the BREAK on the keyboard.

Step 2 - Adding Lines to a Program
Adding Lines to a Program
To add a new line to a program, just type the line number and the BBC Basic code for this new line.

The line will automatically be added to your program in the right position depending on the line number provided.

For instance, add the following lines to your program to create a banner to your Magic 8 Ball program.

20 PRINT "========================"
30 PRINT "| MAGIC 8 BALL |" 
40 PRINT "========================"
Step 3 - Viewing Your Code
Viewing Your Code
To view your whole BBC Basic code type:

LIST

For a long a program you can filter the lines of code you would like to review:

LIST 20,50

This will only show you program from line 20 to line 50.

Step 4 - Editing/Replacing an Existing Line of a Program
Editing/Replacing an Existing Line of a Program
To edit/replace an existing line of code just retype it using the leine number of the line you wish to replace and the new code you would like the line to be replaced with.

For instance in the code above we will replace line 10 which outputs the word “HELLO” with the following code used to clear the screen.

Using the command prompt, type:

10 CLS
Step 5 - Removing a Line of a Program
Removing a Line of a Program
If you do not require a line within your code just type the line number of the line you would like to remove and press RETURN.

For instance to remove line 10, type:

10

To check that the line is gone, check your code:

LIST

Note that we actually need line 10 so you may want to insert it again.

10 CLS
Step 6 - Adding Annotations to Your Code
Adding Annotations to Your Code
As it is good practice to annotate a program we will add a new line of code at the very top of our code, before line 10. We will use a REM command which is used to annotate the code.

5 REM Magic 8 Ball Program - v1.0

Notice how we inserted our new line of code at line 5. This is the reason why, when numbering lines, we tend to always count in 10: This allows us to then insert new lines between two existing lines.

Check your code listing again to see the end result.

With his approach, line numbering can quickly become untidy. From time to time you can ask the BBC Micro to renumber all the lines of your program, starting at line 10 and counting in 10, using the following instruction.

RENUMBER 10,10

Try it with your own code and notice how line 5 is now renumbered as line 10.


So at this stage your whole code should look like this:

10 REM  Magic 8 Ball Program v1.0 
20 CLS
30 PRINT "========================"
40 PRINT "|     MAGIC  8  BALL   |"
50 PRINT "========================"
Step 7 - Saving and Loading a Program
Saving a Program
This program as not been saved yet, so you are at risk of loosing all your code if the computer crashes. to save your work, use the following command:

SAVE MAGIC8

⚠️ Remember, on a BBC Micro filenames can only contain up to 7 characters.

Now that your program is saved, you will be able to reload it at any time using:

LOAD MAGIC8

There is no auto-save features on the BBC Micro so make sure to save your work every so often as you add more lines to your code.

Step 8 - Displaying Instructions on the Screen
Ok great, so now let’s add more lines of code to our program. By doing so you will learn some very useful BBC Basic instructions.

Displaying Instructions on the Screen
Let’s add the following code:

60 PRINT
70 PRINT ">> Ask a YES/NO question, then press RETURN"
80 PRINT

The PRINT instruction is used to display some text on the screen.
When used on its own, the PRINT instruction leaves an empty line for spacing.

Step 9 - Adding the Main Program Loop
Adding a Main Program Loop
We will use a loop so that the end-user can use the Magic 8 Ball to ask as many questions as they wish.

90 REPEAT

This starts a REPEAT-UNTIL loop. All the code between this line and a line starting with UNTILL will be part of our loop.

Step 10 - Asking the User to Input a Question
Asking the Question

100   PRINT "========================"
110   INPUT "Your question: " Q$
120   IF Q$="" THEN PRINT "You must ask a question!":GOTO 110
  • INPUT lets the user type text.
  • Q$ is a string variable (the $ means text).
  • If the user presses RETURN without typing anything:
    • It prints a warning
    • GOTO 110 sends them back to line 110 to ask the user to enter a question again
Step 11 - Choosing a Random Answer
Choosing a Random Answer

130   R = RND(20)

RND(20) gives a random number from 1 to 20.
This number is stored in variable called R (for Response)

This decides which answer the Magic 8 Ball gives.

Step 12 - Displaying the Result
Displaying the Result

140   PRINT
150   PRINT "The Magic 8 Ball says:"
160   PRINT

Just formatting — makes the output look nicer.


The 20 Possible Answers

170   IF R=1  THEN PRINT "It is certain."
180   IF R=2  THEN PRINT "It is decidedly so."
190   IF R=3  THEN PRINT "Without a doubt."
200   IF R=4  THEN PRINT "Yes - definitely."
210   IF R=5  THEN PRINT "You may rely on it."
220   IF R=6  THEN PRINT "As I see it, yes."
230   IF R=7  THEN PRINT "Most likely."
360   IF R=8  THEN PRINT "Outlook good."
240   IF R=9  THEN PRINT "Yes."
250   IF R=10 THEN PRINT "Signs point to yes."
260   IF R=11 THEN PRINT "Reply hazy, try again."
270   IF R=12 THEN PRINT "Ask again later."
280   IF R=13 THEN PRINT "Better not tell you now."
290   IF R=14 THEN PRINT "Cannot predict now."
300   IF R=15 THEN PRINT "Concentrate and ask again."
310   IF R=16 THEN PRINT "Don't count on it."
320   IF R=17 THEN PRINT "My reply is no."
330   IF R=18 THEN PRINT "My sources say no."
340   IF R=19 THEN PRINT "Outlook not so good."
350   IF R=20 THEN PRINT "Very doubtful."

Each IF checks the random number. Only one of these will match. That matching answer is then displayed on screen.

Step 13 - Asking to Play Again?
Asking to Play Again
We will end our program by asking if the user would like to ask another question. This will be useful to use the user answer as a stopping condition for our main program loop.

360   PRINT
370   INPUT "Do you want to ask another question (Y/N)? " A$
380 UNTIL A$="N" OR A$="n"

In the above code:

  • A$ stores the user’s answer
  • The loop continues until the end-user types N or n
    So typing:

      Y → play again, the user will be able to enter another question
      N → stop
Step 14 - Ending the Program
Ending the Program

390 CLS
400 PRINT "Goodbye... the Magic 8 Ball rests!"

The above code will:

  • Clear the screen (CLS)
  • Show a goodbye message (PRINT)
Step 15 - Saving Your Work
Saving your work
You can now test your program using the RUN command and do not forget to save your work using the SAVE command!

SAVE MAGIC8
Full BBC Basic Code
Full BBC Basic Code for the Magic 8 Ball Program:

10 REM  Magic 8 Ball Program v1.0 
20 CLS
30 PRINT "========================"
40 PRINT "|     MAGIC  8  BALL   |"
50 PRINT "========================"
60 PRINT
70 PRINT ">> Ask a YES/NO question, then press RETURN"
80 PRINT
90 REPEAT
100   PRINT "========================"
110   INPUT "Your question: " Q$
120   IF Q$="" THEN PRINT "You must ask a question!":GOTO 110
130   R = RND(20)
140   PRINT
150   PRINT "The Magic 8 Ball says:"
160   PRINT
170   IF R=1  THEN PRINT "It is certain."
180   IF R=2  THEN PRINT "It is decidedly so."
190   IF R=3  THEN PRINT "Without a doubt."
200   IF R=4  THEN PRINT "Yes - definitely."
210   IF R=5  THEN PRINT "You may rely on it."
220   IF R=6  THEN PRINT "As I see it, yes."
230   IF R=7  THEN PRINT "Most likely."
360   IF R=8  THEN PRINT "Outlook good."
240   IF R=9  THEN PRINT "Yes."
250   IF R=10 THEN PRINT "Signs point to yes."
260   IF R=11 THEN PRINT "Reply hazy, try again."
270   IF R=12 THEN PRINT "Ask again later."
280   IF R=13 THEN PRINT "Better not tell you now."
290   IF R=14 THEN PRINT "Cannot predict now."
300   IF R=15 THEN PRINT "Concentrate and ask again."
310   IF R=16 THEN PRINT "Don't count on it."
320   IF R=17 THEN PRINT "My reply is no."
330   IF R=18 THEN PRINT "My sources say no."
340   IF R=19 THEN PRINT "Outlook not so good."
350   IF R=20 THEN PRINT "Very doubtful."
360   PRINT
370   INPUT "Do you want to ask another question (Y/N)? " A$
380 UNTIL A$="N" OR A$="n"
390 CLS
400 PRINT "Goodbye... the Magic 8 Ball rests!"

In the above code, you will noticed that the code within the REPEAT UNTIL loop has been indented (2 spaces at the front of each line of code, between the line number and the code for the line). Though this is not mandatory, it is good practice to indent your code when using loops or IF statements as it makes the code easier to read.

Tagged with: ,

BBC Micro – Organising Files on a Disk

This tutorial is the second of a set of lessons/tutorials that focus on:

BBC Micro Online Emulator

To complete these lessons, you do not need access to a physical BBC micro computer. You can use the following online emulator and type commands in your browser, without the need to install anything on your computer.

You may also find the following BBC Basic emulator quite handy for testing your own BBC Basic programs.

Using Floppy Disk Drives

If you are using a physical computer, remember that the BBC Micro model B does not come with a hard drive to save your work. It is possible to connect a floppy disk drive to save your work on a 5.25″ Double Density floppy disk. Depending on the model of your BBC Micro, you may be able to connect it to a 3.5″ floppy disk drive to use with Double Density (DD) floppy disks with a capacity of around 1MB. This is probably a more reliable solution.

💾 Disk Filing Systems (DFS and ADFS)

The original BBC Micros used a DFS (Disk Filing System) which means they used a flat file structure with a single catalogue of files on the disk. On a DFS system, it is not possible to create a true hierarchical structure using folders/directories.

There is a concept of a directory qualifier — a single letter prefix that groups files (e.g., W.MEMO means file MEMO in directory W which could stand for WORK for instance where G.RACING could be used to store a racing game in directory G for GAMES). This looks like folders but is purely a single-letter categorisation mechanism rather than a true nested directory structure.

With a standard BBC Micro (DFS), you cannot have multiple levels of directories with standard BBC DFS — it’s all in one flat catalogue (with a maximum of 31 files per disk). Also filenames need to be 7 characters or less.

More recent BBC Micros benefited from a more advanced filing system called ADFS (Advanced Disc Filing System) — an upgrade that supports real hierarchical folders/directories, structured in a tree (folders and sub-folders).

This was available on later BBC Micros and upgrades, and later machines like the BBC Master.

💾 Creating, Saving and Loading files on a BBC Micro (DFS)

On the BBC Micro, the main disks operations such as viewing the content of the disk use special commands (starting with *).

📂 Viewing What's on the Disk
For instance to see what files and folders are on the current disk, use the following command:

*CAT

This will show a list of files on the disk.

To simulate opening a directory and hence focus on showing the files from the same group (using the same directory qualifier) use the following command:

*DIR W
*CAT

This would show all the files with the prefix W.

✏️ Typing Your First Program
Using the commend prompt, type the following code (including the line numbers):

10 MODE 2
20 COLOUR RND(7)
30 PRINT "HELLO WORLD"
40 GOTO 20

This program is written in a language called BBC Basic, a language created with the aim of making computer programming accessible to beginners through a simple yet powerful language on the BBC Micro computer.

You can now run this code by pressing the following command:

RUN

⚠️ To stop this program, press the BREAK key on the keyboard.

💾 Saving Files

After typing and testing your program, you will want to save it to the disk. Use the following command to do so:

SAVE "HELLO"

It will be saved on the disk with the filename HELLO.
⚠️Remember, on the BBC Micro file names cannot exceed 7 characters!

To save this file into a specific group (such as your WORK group: W):

SAVE "W.HELLO"

This saves HELLO within the W group. Remember groups are an alternative to the use of folders/directories as these cannot be created within a standard BBC Micro (DFS).

📃 Loading a Program into Memory
To load the program:

LOAD "HELLO"

This copies the program from disk into the computer’s memory.

You can check it loaded by typing:

LIST

You should now see your program lines on the screen.

▶️ Running the Program
To run the program after loading it:

RUN

Your program will now start.

⚡ Quick Way: Load and Run in One Command
You can also load and run a program in one step using:

CHAIN "HELLO"

This is very commonly used for games and larger programs.

✏️ Renaming Files
To rename a file:

*RENAME oldname newname

Example:

*RENAME HELLO TEST

This renames file HELLO to TEST.

⚠️ Be careful — if the new name already exists, it may overwrite it.

🗑 Deleting Files
To delete a file:

*DELETE filename

Example:

*DELETE OLDGAME

⚠️ Deleted files cannot be recovered.

✏️ Editing a Program
If you want to edit an existing progam, you first need to make sure it is already loaded in memory:

LOAD HELLO

Then you can view the code of this program using the following command:

LIST

✏️ To change an existing line of your program

If your program has:

10 PRINT "HELLO"

and you want to change it to say:

10 PRINT "HELLO WORLD"

Just type:

10 PRINT "HELLO WORLD"

and press RETURN.

Line 10 is now replaced.

➕ Adding New Lines

To add a new line between 10 and 20, use a number in between:

15 PRINT "WELCOME!"

BBC BASIC keeps the program in number order automatically.

️➖ Deleting a Line

To delete line 15, type:

15

and press RETURN.

That line is removed from the program.

📃 Listing Part of a Program

To see only part of the program, type the following command:

LIST 10,50

This lists lines 10 to 50 only. This is very useful when working on a long program.

💾 Saving Your Changes

After editing, save again to keep your changes:

SAVE "HELLO"

This overwrites the old version with the new one.

⚠️ If you want to keep both versions, use a new name:

SAVE "HELLO2"

⭐ Extra Tip: Renumbering Lines

If after inserting and removing lines, your line numbers get messy, you can renumber the whole program:

RENUMBER

or even better, using the following command:

RENUMBER 10,10

(start at 10, count by 10)
This makes it easier to insert new lines later.

Your Task

Use all of the above commands to recreate the following file structure on your BBC Micro Computer or using the online emulator.

D.HELLO
D.SPLASH
W.TIMES
W.MOON
W.PASS

In the above file structure D stands for DEMO and W stands for WORK.

Our four files will contain the code provided in the four tabs below:

D.HELLO fileD.SPLASH fileW.TIMES fileW.MOON fileW.PASS file
D.HELLO file:
A colourful “Hello World” program.

10 MODE 2
20 COLOUR RND(7)
30 PRINT "HELLO WORLD"
40 GOTO 20
D.SPLASH file:
This code is a demo of a splash screen using blinking red text.

10 MODE 7
20 PRINT CHR$(136)CHR$(129)"SPLASH SCREEN!"
W.TIMES file:
A program used to generate a times table:

10 REM Times Table Generator
20 INPUT "Enter a number: " ; n
30 PRINT
40 FOR i = 1 TO 10
50   PRINT n; " x "; i; " = "; n*i
60 NEXT
W.MOON file:
A program to caluculate you weight on the Moon!

10 REM Weight on the Moon Calculator
20 INPUT "Enter your weight on Earth in kg: " ; weight
30 moon = weight / 6
40 PRINT
50 PRINT "Your weight on the Moon would be:"
60 PRINT moon; " kg"
W.PASS file:
A program used to generate a random password:

10 REM PASSWORD GENERATOR
20 password$ = ""
30 FOR i = 1 TO 8
40 r = RND(36) - 1
50 IF r < 26 password$ = password$ + CHR$(65 + r) ELSE password$ = password$ + CHR$(48 + r - 26)
60 NEXT
70 PRINT "Password: "; password$
Tagged with: ,

Getting Started with the BBC Micro (Model B)

The BBC Microcomputer Model B (often called the Beeb) was a popular computer in UK schools in the 1980s. It was made in the UK by Acorn Computers Ltd. During its lifespan there were over 1.5 million units manufactured from 1981 to 1994. It was designed to help people learn programming and understand how computers work.

This tutorial is the first of a set of lessons/tutorials that focus on:

BBC Micro Online Emulator

To complete these lessons, you do not need access to a physical BBC micro computer. You can use the following online emulator and type commands in your browser, without the need to install anything on your computer.

You may also find the following BBC Basic emulator quite handy for testing your own BBC Basic programs.

Getting Started with a BBC Micro (or using an online emulator!)

This first “Getting Started” tutorial will help you turn your BBC Micro on, type commands, and run your first program.

1. Connecting the BBC Micro

If you are using the online emulator, you can bypass this section.
Otherwise, if you are working with a real BBC Micro computer, you will need:

  • ✅ BBC Micro Model B computer
  • ✅ Power cable
  • ✅ Display (TV or monitor with suitable SCART cable or SCART to HDMI converter)

The BBC Micro has a built-in keyboard. There is no mouse but some advanced gamers would use a joystick to play video games.

BBC Micro Computer Model B

The BBC Micro model B does not come with a hard drive to save your work. It is possible to connect a floppy disk drive to save your work on a 5.25″ floppy disk. Depending on the model of your BBC Micro, you may be able to connect it to a 3.5″ floppy disk drive to use with Double Density (DD) floppy disks with a capacity of around 1MB. This is probably a more reliable solution.

To start your BBC Micro, you should:

  1. Turn on the monitor first.
  2. Switch on the BBC Micro using the switch at the back.

After a few seconds you should see:

BBC Computer
Acorn DFS

>

The > symbol is the command prompt. This means the computer is ready for instructions.

About the keyboard:
The keyboard is simlar in may ways with a modern QWERTY keyboard, You will find the following four keys particularly useful:

  • RETURN key → same as Enter
  • DELETE key → same as a backspace key
  • BREAK key → stops a program and resets the computer.
    ⚠️ Pressing BREAK will clear anything currently running.
  • SHIFT key → for capital letters and symbols
⌨️ 2. Typing Your First Command

Let’s try a simple command.

At the > prompt, type:
PRINT "HELLO WORLD"

Then press RETURN.

You should see:
HELLO WORLD
Well done — you’ve just told the computer to display text!

3. Writing Your First Program

Now let’s write a small program in BBC BASIC.

Type the following exactly (including the line numbers):

10 PRINT "HELLO BBC MICRO!"
20 GOTO 10

Press RETURN after each line.

Now type:

RUN

and press RETURN.

The message will repeat over and over on the screen.

⚠️ To stop it, press the BREAK key on the keyboard.

Let’s improve the output of this Hello World program by adding some colours:

10 MODE 2
20 COLOUR RND(7)
30 PRINT "HELLO WORLD"
40 GOTO 20

Here is what your code will produce when you run it:


You can now continue through our set of 4 lessons on how to use the BBC Micro to code basic Programs in BBC Basic. (See links at the top of this page).

You may also find the original BBC Micro User Guide very useful to learn everything there is to know about the BBC Micro!

Tagged with: ,

Computer Hardware: CPU and Memory – Crossword

crosswordHow well do you really know the inner workings of a computer? From the lightning-fast calculations of the CPU to the different types of memory that store data, computer hardware is full of essential components that quietly power everything we do.

In this crossword, we are focusing on three core areas of computer hardware:

The CPU (Central Processing Unit) – A complex microchip responsible for executing instructions, performing calculations, and coordinating the activities of all other components.

Primary memory – the fast, short-term memory a computer uses to store data and instructions that are actively in use. This includes components like RAM, which allow programs to run smoothly and efficiently.

Secondary memory – the long-term storage that keeps data (files, applications, and operating systems) even when the computer is turned off. Magnetic hard drives, SSDs and other storage devices fall into this category.

Computer Hardware CrosswordOpen Crossword Puzzle in a New Window
Computer Hardware CrosswordOpen Crossword Puzzle in a New Window
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Computer Science Legislation (UK) – Take the Quiz

When people use computers, phones and the internet, they create and share huge amounts of data and digital content. To protect people and organisations, the UK has several important laws that control how technology can be used.

In this activity, you will be sorting real-world inspired case files into the correct legal category. Before you start, here is a quick reminder of the three main UK laws you need to know for Computer Science and Digital Technology courses.

In the UK, there are three main acts that are very relevant to the use of computer science technologies:

  1. The Copyright, Designs & Patents Act
  2. The Data Protection Act
  3. The Computer Misuse Act

Let’s find out more about this legislation.

The Data Protection ActThe Computer Misuse ActThe Copyright, Designs & Patents Act

The Data Protection Act

The Data Protection Act works alongside GDPR (General Data Protection Regulation) to protect people’s personal data.

The purpose of this act is to ensure our personal data is being used and dealt with sensibly.

Example of personal data:

  • Name and address
  • Date of birth
  • Employment records
  • Medical records
  • Religion/faith

This act stipulates that personal information stored on a computer system must be kept securely.

Personal data shall be processed fairly and lawfully in accordance with the rights of data subjects.

When an organisation stores personal data about individuals on a computer system, they must only store data that is relevant/necessary, accurate and up-to-date.

Personal data kept by an organisation on a computer system shall not be kept for longer than is necessary and should be deleted if it is no longer needed.

When personal data is shared with a third party, it has to be done fairly and lawfully, securely and with the permission of the data subject.

The Computer Misuse Act

The purpose of this act is to discourage people from accessing computer systems without permission (hacking) whether to intend to commit further illegal activities or not.

This acts make it illegal to access data on a computer when that material will be used to commit further illegal activity, such as fraud or blackmail.

It is also illegal to access and change the contents of someone’s files without their permission. It is therefore illegal to install a virus or other malware on someone’s computer as this is done without their consent.

This act also makes it illegal to carry out attacks that stop systems from working (e.g. DDoS attacks)

The Copyright, Designs & Patents Act

This act provides a legal means of ensuring that content creators can protect the work they have produced.

When anyone creates something, they automatically own it. This could include:

  • a picture, drawing or photograph
  • an animation, a film or a video clip
  • a sound file, podcast or music
  • a piece of text incl. an article, news report, blog post or a book
  • a video game or a computer program (e.g. source code)

When using copyrighted material, it is illegal to…

  • Make copies
  • Publish
  • Distribute
  • Sell copies

…unless you have been given permission by the copyright owner.

UK Legislation Quiz

You will now be shown a series of case files based on real events involving:

  • Data leaks
  • Hacking attacks
  • Illegal sharing of digital content

Your task is to:

  1. Read each case carefully
  2. Decide which law it is most closely related to
  3. Drag the case into the correct legal folder

You can change your mind and move cases again before finishing!

Can you correctly sort all the cases and get a perfect score? Good luck, and think carefully about which law applies in each situation!
UK Legislation – Drag and DropOpen in New Window